package org.bigjava.travel.provider;

import org.springframework.stereotype.Component;

/**
 * 酒店SQL语句封装类
 */

@Component
public class HotelSqlProvider {

    //查询所有的发布的酒店信息
    public String count(){ return "SELECT count(*) FROM t_hotel WHERE DELETE_STATUS=0 AND STATE=1"; }

    //查询所有的酒店信息
    public String count2(){ return "SELECT count(*) FROM t_hotel WHERE DELETE_STATUS=0 "; }

    //通过ID查询酒店
    public String findById() {
        return "SELECT * FROM t_hotel WHERE ID = #{id} AND DELETE_STATUS=0";
    }

    //通过ID给酒店排序
    public String findList(){
        return "SELECT * FROM t_hotel WHERE DELETE_STATUS=0 ORDER BY ID ASC";
    }

    //通过添加时间给酒店排序
    public String indexList(){
        return "SELECT * FROM t_hotel WHERE DELETE_STATUS=0 AND STATE=1 ORDER BY ADD_TIME DESC";
    }

    //通过酒店名称模糊查询
    public String findListByQuery(){
        return "SELECT * FROM t_cms_hotel WHERE DELETE_STATUS=0 AND HOTEL_NAME LIKE #{query,jdbcType=VARCHAR} ORDER BY ID ASC";
    }

    //修改酒店信息
    public String update(){
        return "UPDATE t_hotel SET HOTEL_NAME=#{hotelName}, HOTEL_INTRO=#{hotelIntro},HOTEL_STAR=#{hotelStar},LINK_PHONE=#{linkPhone}," +
                "ADDRESS=#{address},STATE=#{state},IMG_URL=#{imgUrl},PRICE=#{price} WHERE ID=#{id}";
    }

    //保存酒店
    public String save(){
        return "INSERT INTO t_hotel(ADD_TIME,HOTEL_NAME,HOTEL_INTRO,HOTEL_STAR,LINK_PHONE,ADDRESS,STATE, IMG_URL,PRICE) " +
                "VALUES(NOW(),#{hotelName},#{hotelIntro},#{hotelStar},#{linkPhone},#{address},#{state},#{imgUrl},#{price})";
    }

    //通过id删除
    public String deleteById(){
        return "UPDATE t_hotel SET DELETE_STATUS=1 WHERE id=#{id}";
    }


    public String state0count(){ return "SELECT count(*) FROM t_hotel WHERE DELETE_STATUS=0 AND STATE=0"; }
    public String state1count(){ return "SELECT count(*) FROM t_hotel WHERE DELETE_STATUS=0 AND STATE=1"; }
    public String state2count(){ return "SELECT count(*) FROM t_hotel WHERE DELETE_STATUS=0 AND STATE=2"; }

}
